<?php

	include("common.php");
	
	if(!empty($_POST)){
		$keys = $_POST['key'];
		$rows = $_POST['row'];
		foreach($keys as $key => $name){
			$value = $rows[$key];
			mysql_query("UPDATE `197_settings` SET `value` = '" . $value . "' WHERE `name` = '" . $name . "'");
		}
		
		include("header.php");
		
?>
<h1>修改設定值</h1>
<p>修改成功，請<a href="settings.php">按此</a>返回。</p>
<?php

		include("sidebar.php");
		include("footer.php");
		exit;
	}
	
?>
<?php include("header.php"); ?>
<script type="text/javascript" src="../jquery/js/jquery.tools.min.js"></script>
<script type="text/javascript" src="../jquery/js/shCore.js"></script>
<script type="text/javascript" src="../jquery/js/shBrushPhp.js"></script>
<script type="text/javascript" src="../jquery/js/shBrushXml.js"></script>
<script type="text/javascript" src="../jquery/js/shBrushJScript.js"></script>
<link rel="stylesheet" href="../jquery/css/simple-overlay.css" />
<link rel="stylesheet" href="../jquery/css/shCore.css" />
<link rel="stylesheet" href="../jquery/css/shThemeDefault.css" />
<h1>編輯設定</h1>
<div id="setting-add" class="simple-overlay">
	<form action="settingsAdd.php" id="add-setting-form" method="POST">
		<p><label>名稱：<input type="text" id="name" name="name" /></label></p>
		<p><label>設定值：<input type="text" id="value" name="value" /></label></p>
		<p><button class="custom" onclick="$('#setting-add').submit();">新增</button></p>
	</form>
</div>
<div id="setting-delete" class="simple-overlay">
	<p>確定刪除設定值『<span id="setting-delete-name"></span>』？</p>
	<p><button class="custom" id="setting-delete-button">確定</button></p>
</div>
<div id="setting-help" class="simple-overlay-wide">
	<h2>如何調用？(PHP)</h2>
	<h4>顯示站台名稱</h4>
	<pre class="brush: php">
		&lt;?php
			echo $set['site_name'];
		?&gt;</pre>
	<h4>顯示Logo</h4>
	<pre class="brush: html">
		&lt;img src="&lt;?php echo $set['site_name']; ?&gt;" /&gt;</pre>
	<h2>如何調用？(JavaScript)</h2>
	<h4>跳出站台名稱</h4>
	<pre class="brush: js">
		function alertSiteName(){
			alert(setting["site_name"]);
		}
		
		alertSiteName();</pre>
	<script type="text/javascript">
    	SyntaxHighlighter.all()
	</script>
</div>
<script type="text/javascript">

	$("#setting-delete").overlay({
		mask: {
			color: '#ebecff',
			loadSpeed: 200,
			opacity: 0.9
		},
	
		closeOnClick: false
	});
	
	$("#setting-help").overlay({
		mask: {
			color: '#ebecff',
			loadSpeed: 200,
			opacity: 0.9
		},
		
	
		closeOnClick: false
	});
	
	function doDelete(name){
		$("#setting-delete").html("<img src='../images/ajax-loader.gif' />");
		$("#setting-delete").load("settingsDelete.php?ajax=true&name=" + name);
		return;
	}
	
	function deleteSetting(name){
		$("#setting-delete-name").html(name);
		var dialogApi = $("#setting-delete").data("overlay");
		dialogApi.load();
		$("#setting-delete-button").click(function(){ doDelete(name); });
	}
	
	function showHelp(){
		var dialogApi = $("#setting-help").data("overlay");
		dialogApi.load();
	}
	
</script>
<form action="settings.php" id="settings-form" method="POST">
	<table style="border: 1px #333 solid; padding: 5px; width: 98%;">
		<tr>
			<td>設定名稱</td>
			<td>設定值</td>
		</tr>
		<?php foreach($set as $key => $row){ ?>
			<tr>
				<td><input name="key[]" type="hidden" value="<?php echo $key; ?>" /><?php echo $key; ?></td>
				<td><input name="row[]" type="text" style="width: 85%;" value="<?php echo $row; ?>" /><span style="color: #F00;"><a href="javascript:void(0);" onclick="deleteSetting('<?php echo $key; ?>');">刪除</a></span></td>
			</tr>
		<?php } ?>
	</table>
	<p><button class="custom" onclick="$('#settings-form').submit();">確定</button>｜<button class="custom dialog" rel="#setting-add">新增</button>｜<button onclick="showHelp(); return false;" class="custom">說明</button></p>
</form>
<script type="text/javascript">
	$(".dialog").overlay({
	
		// some mask tweaks suitable for modal dialogs
		effect: 'apple',
		
		mask: {
			color: '#ebecff',
			loadSpeed: 200,
			opacity: 0.9
		},
	
		closeOnClick: false
	});
</script>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>